package com.ruoyi.project.dict.zyzx.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.dict.zyzx.domain.Zyzx;
import com.ruoyi.project.dict.zyzx.service.IZyzxService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 字源字形Controller
 * 
 * @author shixiangwen
 * @date 2021-03-16
 */
@Controller
@RequestMapping("/dict/zyzx")
public class ZyzxController extends BaseController
{
    private String prefix = "dict/zyzx";

    @Autowired
    private IZyzxService zyzxService;

    @RequiresPermissions("dict:zyzx:view")
    @GetMapping()
    public String zyzx()
    {
        return prefix + "/zyzx";
    }

    /**
     * 查询字源字形列表
     */
    @RequiresPermissions("dict:zyzx:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Zyzx zyzx)
    {
        startPage();
        List<Zyzx> list = zyzxService.selectZyzxList(zyzx);
        return getDataTable(list);
    }

    /**
     * 导出字源字形列表
     */
    @RequiresPermissions("dict:zyzx:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Zyzx zyzx)
    {
        List<Zyzx> list = zyzxService.selectZyzxList(zyzx);
        ExcelUtil<Zyzx> util = new ExcelUtil<Zyzx>(Zyzx.class);
        return util.exportExcel(list, "zyzx");
    }

    /**
     * 新增字源字形
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存字源字形
     */
    @RequiresPermissions("dict:zyzx:add")
    @Log(title = "字源字形", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Zyzx zyzx)
    {
        return toAjax(zyzxService.insertZyzx(zyzx));
    }

    /**
     * 修改字源字形
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Zyzx zyzx = zyzxService.selectZyzxById(id);
        mmap.put("zyzx", zyzx);
        return prefix + "/edit";
    }

    /**
     * 修改保存字源字形
     */
    @RequiresPermissions("dict:zyzx:edit")
    @Log(title = "字源字形", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Zyzx zyzx)
    {
        return toAjax(zyzxService.updateZyzx(zyzx));
    }

    /**
     * 删除字源字形
     */
    @RequiresPermissions("dict:zyzx:remove")
    @Log(title = "字源字形", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zyzxService.deleteZyzxByIds(ids));
    }
}
